<?php
/**
 * crcl/base
 *
 * Copyright 2013 CRCL - André Sabosch - info@crcl.de
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace crcl\base;

interface IFilter
{
  //you can use getInstance (factory)
  //or:

  public static function mysqlIdentifier();
  public static function quote();
  public static function lowercase();
  public static function trim();
}

class Filter extends instance\Factory implements IFilter
{
  const TYPE_MYSQLIDENTIFIER = 'mysqlIdentifier://';
  const TYPE_QUOTE = 'quote://';
  const TYPE_LOWERCASE = 'lowercase://';
  const TYPE_TRIM = 'trim://';

  public static function mysqlIdentifier()
  {
    return self::getInstance(self::TYPE_MYSQLIDENTIFIER);
  }

  public static function quote()
  {
    return self::getInstance(self::TYPE_QUOTE);
  }

  public static function lowercase()
  {
    return self::getInstance(self::TYPE_LOWERCASE);
  }

  public static function trim()
  {
    return self::getInstance(self::TYPE_TRIM);
  }

  public static function getInstance($sUri)
  {
    if (\strpos($sUri, '://') === \FALSE)
    {
      $sUri = String::getInstance($sUri)
              ->doEndWith('://')
              ->toString();
    }
    return parent::getInstance($sUri);
  }

  /** PROTECTED ***********************************************************************************/

  protected static $sFactoryDirectory = 'filter/container';
  protected static $aFactoryAllowedTypes = array('mysqlIdentifier', 'quote', 'lowercase', 'trim');
}

/*

interface IFilter
{
  public static function datetime($sFormat = 'Y-m-d H:i:s');
  public static function date($sFormat = 'Y-m-d');
  public static function year();
  public static function time($sFormat = 'H:i:s');
  public static function mail();
  public static function normalize();
  public static function arrayToSet();
  public static function removeWhitespace();
  public static function url();
  public static function phone();
  public static function float();
  public static function name();
  public static function shortname();
}


  private static function _factory($sType, $detail = \NULL)
  {
    //the factory is only called internally, so we are sure,
    //everything works fine, no errorhandling
    $sFile = dirname(__FILE__) . '/filter/' . $sType . '.php';
    require_once $sFile;
    $sClass = '\base\filter\\' . $sType;
    $oFilter = new $sClass();
    if (!\is_null($detail))
    {
      $oFilter->setDetail($detail);
    }
    return $oFilter;
  }
} */